import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * ClassName: Test <br/>
 * Description: <br/>
 * date: 2020/8/4 9:41<br/>
 *
 * @author Hesion<br/>
 * @version
 * @since JDK 1.8
 */
object GlomTest {
  def main(args: Array[String]): Unit = {
    //TODO 1.创建SparkContext
    val conf = new SparkConf().setMaster("local[*]").setAppName("File-RDD")
    val sc = new SparkContext(conf)

    //glom  计算所有分区最大值求和
    val dataRdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 5, 6), 3)
    val glomRdd: RDD[Array[Int]] = dataRdd.glom()
    val maxRdd: RDD[Int] = glomRdd.map(array => array.max)
    val array: Array[Int] = maxRdd.collect()

    println(array.sum)
  }
}
